//
//  KSTabBarController.m
//  KQVH_G
//
//  Created by 郭树清 on 16/12/6.
//  Copyright © 2016年 KuoShuChing. All rights reserved.
//

#import "KSTabBarController.h"
#import "UIColor+KQExpanded.h"
#import "UIImage+KQExtension.h"
#import "UIView+KQFraneExtension.h"
#import "KSNavigationController.h"
#import "DEMineMainTabbarController.h"
//#import "DENeighbourViewController.h"
//#import "DECommunityServiceViewController.h"
//#import "DEGIdelShareViewController.h"
//#import "DEMineViewController.h"

@interface KSTabBarController ()<UITabBarControllerDelegate>
{
   BOOL isComment;
}
@property (nonatomic,strong) UINavigationController *nav;
@end

@implementation KSTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置应用程序中所有的UITabBarItem的属性
//    [self setUptabbarItem];
    //初始化我们的子控制器
    [self setupChildVC];
    
    self.delegate = self;
}

////设置应用程序中所有的UITabBarItem的属性
//- (void)setUptabbarItem{
//    UITabBarItem * item = [UITabBarItem appearance];//认为是一个皮肤
//    //属性字典
//    NSDictionary * dict = @{
//                            NSFontAttributeName : [UIFont systemFontOfSize:12],
//                            NSForegroundColorAttributeName : [UIColor grayColor]
//                            };
//    NSDictionary * dictSelect = @{ NSForegroundColorAttributeName : [UIColor darkGrayColor]};
//    
//    [item setTitleTextAttributes:dict forState:UIControlStateNormal];
//    [item setTitleTextAttributes:dictSelect forState:UIControlStateSelected];
//    
//    KSTabBar * tabBar = [[KSTabBar alloc]init];
//    [self setValue:tabBar forKey:@"tabBar"];
//}

//初始化我们的子控制器
- (void)setupChildVC{
    //邻里关系
//    [self setUpChildViewController:[[DENeighbourViewController alloc]init] title:@"邻里关系" imageNamed:@"邻里关系-未选中" selectedImageNamed:@"邻里关系-选中"];
//
//    //社区服务
//    [self setUpChildViewController:[[DECommunityServiceViewController alloc]init] title:@"社区服务" imageNamed:@"社区服务-未选中" selectedImageNamed:@"社区服务-选中"];
//
//    //闲置共享
//    [self setUpChildViewController:[[DEGIdelShareViewController alloc]init] title:@"闲置共享" imageNamed:@"闲置共享-未选中" selectedImageNamed:@"闲置共享-选中"];
//
//
//    //我的
//    [self setUpChildViewController:[[DEMineViewController alloc]init] title:@"我的" imageNamed:@"我的-未选中" selectedImageNamed:@"我的-选中"];
    
}
-(void)setUpChildViewController:(UIViewController *)vc title:(NSString *)title imageNamed:(NSString *)imageName selectedImageNamed:(NSString *)selectedImageName
{
    
    UINavigationController *nav = [[KSNavigationController alloc]initWithRootViewController:vc];
    vc.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:imageName];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName].originarImage;
    vc.tabBarController.tabBar.barTintColor = [UIColor hexStringToColor:@"#ff8900"];
    
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] =[UIColor hexStringToColor:@"#888888"];
    
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor hexStringToColor:@"#ff8900"];
    
    [vc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [vc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];

    
    //设置文字 注意:文字大小只能在Normal状态下设置
    [self addChildViewController:nav];
}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController{
}

//- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
//{
//
//    self.nav = (KSNavigationController *)viewController;
//
//    if([self.nav.childViewControllers.firstObject isKindOfClass:[DEMineViewController class]]){
//
//        UINavigationController *currentNav =  tabBarController.childViewControllers[tabBarController.selectedIndex];
//        //        UIWindow * window = [[UIApplication sharedApplication] keyWindow];
//        //        UIViewController *rootVC = window.rootViewController;
//        UIViewController *presentedViewController = currentNav.parentViewController;
//
//        DEMineMainTabbarController *tabBarVC  = [[DEMineMainTabbarController alloc]init];
//        // 隐藏 tarBar
//        //            self . tabBarController . tabBar . hidden = YES ;
//        // 隐藏导航栏
//        //        [currentNav pushViewController:tabBarVC animated : NO ];
//        tabBarVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
//        [presentedViewController presentViewController:tabBarVC animated:YES completion:nil];
//
//
//        return NO;
//    }
//    else if ([self.nav.childViewControllers.firstObject isKindOfClass:[DECommunityServiceViewController class]])
//    {
//
//        return YES;
//    }
//    else
//    {
//        return YES;
//    }
//}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
